<?php

namespace App\Models\GameDB\LotteryDraw;

use Illuminate\Database\Eloquent\Model;

class AddPoolConfig extends Model
{
    public $connection = 'mysql_game';

    protected $table = 'lottery_pet_draw_add_pool_config';

    public $timestamps = true;

    public function relation()
    {
        return $this->morphTo();
    }

    //判断补池金额是否需要增加，返回金额
    public function checkPool($tag, $game_type, $group_id)
    {
        $result = ['add_money' => 0];
        $where = [
            'tag' => $tag,
            'game_type' => $game_type,
            'relation_id' => $group_id,
        ];
        $data = $this->where($where)->first();

        if (empty($data->rate)) {
            return $result;
        }
        $rand = rand(1, 100);
        $add_money = 0;
        if ($rand <= $data->rate) {
            $add_money = $data->add_money;
        }
        return [
            'add_money' => $add_money,
            'config_id' => $data->id,
        ];
    }

    public function admin()
    {
        return $this->hasOne(\App\Models\GameDB\Admin::class, 'auth_id', 'admin_id');
    }

}
